//
//  UIBarButtonItem+Extensions.swift
//  智微博
//
//  Created by mac1 on 2017/4/19.
//  Copyright © 2017年 Y&Q. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
  
  

  
  
  /// 创建 UIBarbuttonItem
  ///
  /// - Parameters:
  ///   - title: title
  ///   - fontSize: 默认 16 号
  ///   - target: target
  ///   - action: action
  ///   - isBack 是否返回按钮 如果是 加上箭头
  // convenience init(title:String,fontSize:CGFloat = 16,target:AnyObject?,action:Selector) {
    // 为了减小改动 增加默认值
  convenience init(title:String,fontSize:CGFloat = 16,target:AnyObject?,action:Selector,isBack:Bool = false) {

    
    let btn:UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
    
    
    
    if isBack {
      let imageName = "navigationbar_back_withtext"
      btn.setImage(UIImage(named:imageName), for: .normal)
      btn.setImage(UIImage(named:imageName + "_highlighted"), for: .highlighted)
      btn.sizeToFit()
    }
    
    btn.addTarget(target, action: action, for: .touchUpInside)
    
    // self.init 实例化 UIBarButtonItem
    self.init(customView: btn)
  }
  
}
